<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<% String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>新增拖车渠道信息</title>
<jsp:include page="../../import.jsp" flush="true" />
<%--<jsp:include page="assParkCommon.jsp" flush="true" /><!-- 时间格式转换 -->--%>
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
            <div id="pageInTab" class="pageInTab">
                <div tabid="baseInfo" title="基本信息" lselected="true">
                    <form id="assTrailCarChnFormSet">
                        <div class="fieldset1 tabel_col clearFix">
                        <div class="caption">
                            <span class="title">新增拖车渠道信息</span>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">渠道类型</div>
                            <div class="field">
                                <select name="channelTypeCd" id="channelTypeCd" data-value=" " validate ="{required:true,select:true}" onchange="cstTypCdFun(this.value)">
                                    <option value=" " selected="selected" >请选择</option>
                                    <c:forEach items="${cstTypCdList }" var="kv">
                                        <option value="${kv.key }">${kv.value }</option>
                                    </c:forEach>
                                </select>
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">渠道备案省</div>
                            <div class="field">
                                <select name="recordPrCd" id="recordPrCd" data-value=" " validate ="{required:true,select:true}">
                                    <option value=" " selected="selected" >请选择</option>
                                    <c:forEach items="${provinceKVList }" var="province">
                                        <option value="${province.key }">${province.value }</option>
                                    </c:forEach>
                                </select>
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">渠道名称</div>
                            <div class="field">
                                <input name="channelNm" id="channelNm" value="" type="text" class="ui-textbox" validate="{required:true}">
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">身份证号</div>
                            <div class="field">
                                <input name="idNo" id="idNo" type="text" class="ui-textbox" value="" validate="{required:true, idcardno:true}">
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">联系电话</div>
                            <div class="field">
                                <input name="mp" id="mp" type="text" class="ui-textbox" value="" validate="{required:true, mobileAndFixedPhone:true}">
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">邮箱</div>
                            <div class="field">
                                <input name="email" id="email" type="text" class="ui-textbox" value="" validate="{email:true}">
                            </div>
                        </div>
                        <div class="fieldBox col_33" id="succDiv">
                            <div class="label">统一社会信用代码</div>
                            <div class="field">
                                <input name="succ" id="succ" type="text" class="ui-textbox" value="" validate="{required:true, alnum:true}">
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33" id="corpRepDiv">
                            <div class="label">法人代表</div>
                            <div class="field">
                                <input name="corpRep" id="corpRep" type="text" class="ui-textbox" value="" validate="{required:true}">
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">日常所在地</div>
                            <div class="field">
                                <input name="dailyAddr" id="dailyAddr" type="text" class="ui-textbox" value="" validate="{required:true}">
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">成立日期</div>
                            <div class="field">
                                <input name="regDt" id="regDt" type="text" class="ui-datepicker" value="" validate="{required:true}">
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33" id="regCapAmtDiv">
                            <div class="label">注册资本(元)</div>
                            <div class="field">
                                <input name="regCapAmt" id="regCapAmt" type="text" class="ui-textbox" value="" validate="{number:true}">
                            </div>
                        </div>
                        <div class="fieldBox col_33" id="expDtDiv">
                            <div class="label">营业期限</div>
                            <div class="field">
                                <input name="expDt" id="expDt" type="text" class="ui-datepicker" value="" >
                            </div>
                        </div>
                        <div class="fieldBox col_100">
                            <div class="label">地址</div>
                            <div class="field">
                                <input name="addr" id="addr" type="text" class="ui-textbox" value="" validate="{required:true}">
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">合作模式</div>
                            <div class="field">
                                <input type="text" id="coopTypCd" name="coopTypCd" placeholder="请选择" validate="{required:true}" ltype="combobox"/>
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>
                        <div class="fieldBox col_66">
                            <div class="label">地区</div>
                            <div class="field">
                                <input type="text" id="rgnCd" name="rgnCd" placeholder="请选择" validate="{required:true}" ltype="combobox"/>
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>
                        <div class="fieldBox col_100">
                            <div class="label">附件上传</div>
                            <div class="field">
                                <jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload2.jsp" flush="true" >
                                    <jsp:param name="filePath" value="/ass"/>
                                </jsp:include>
                                <%--<input  id="pkId"  name="pkId"  type="hidden"  value="${dtlId}">--%>
                            </div>
                        </div>
                        <%--<div class="fieldBox col_100">--%>
                            <%--<div class="label">附件上传</div>--%>
                            <%--<div class="field">--%>
                                <%--<jsp:include page="../assCommFilesUpload.jsp" flush="true" >--%>
                                    <%--<jsp:param name="filePath" value="ass"/>--%>
                                <%--</jsp:include>--%>
                                <%--<div id="fileUpload1" class="upfileBoxs"></div>--%>
                                <%--<span class="sq-button sq-button-hasicon" id="btnUpload1" onclick="ajaxFileUploadImg('uploads1',1)">--%>
                                    <%--<i class="sqBtnIco_9"></i>上传--%>
                                <%--</span>--%>
                            <%--</div>--%>
                        <%--</div>--%>
                        <div class="fieldBox col_100">
                            <div class="label">备案信息</div>
                            <div class="field">
                                <textarea name="recordInfo" id="recordInfo" rows="6" class="ui-textarea l-textarea" style="width:80%" value="" validate="{maxlength:200}"></textarea>
                            </div>
                        </div>
                        <!-- 隐藏主键、系统代码(融资租赁系统)
                        <div class="fieldBox col_100" style="display:none;">
                            <div class="field">
                                 <input name="cId" id="cId" type="text" class="ui-textbox" value="${id}">
                            </div>
                        </div>-->
                    </div>

                    <div class="btnsBox">
                        <span id="saveAssParkingInfoBtn" class="sq-button sq-button-round" onclick="saveAssTrailCarChnInfo()">保存</span>
                        <span id="closeBtn" class="sq-button sq-button-round" onclick="Remove_navTab()">关闭</span>
                        <input name="chnId" id="chnId" type="hidden" value="${id}">
                    </div>
                </form>
                </div>
                <div tabid="bankAcc" title="银行账号">
                    <iframe frameborder="0" src=""></iframe>
                </div>
            </div>
		</div>
	</div>
	<script type="text/javascript">

        var grid = null;
        var pageInApp = {};
        var loadedTabs = [];
        //初始加载
        $(function () {
            initComBox();//初始合作模式 和 地区下拉
            //标签页
            pageInTab = $("#pageInTab").ligerTab({
                height: 'auto',
                contextmenu: false,
                minIframeHeight: GET_minIframeHeight(),
                onBeforeSelectTabItem: function (tabid) {
                    var chnId = $("#chnId").val();
                    if(tabid!="baseInfo"){
                        if(!chnId){
                            top.$.ligerDialog.SQalert({content: "请确认拖车渠道信息已存在", SQ_type: "warning"});
                            return false;
                        }
                    }
                },
                onAfterSelectTabItem: function (tabid) {
                    if (loadedTabs.indexOf(tabid) < 0) {
                        var chnId = $("#chnId").val();
                        if(tabid!="tabA"){
                            if(!chnId){
                                top.$.ligerDialog.SQalert({content: "请确认经销商基本信息已存在", SQ_type: "warning"});
                                return false;
                            }
                        }
                        loadedTabs.push(tabid);
                        switch (tabid) {
                            case "bankAcc":
                                pageInTab.setTabItemSrc(tabid, "<%=path%>/ass/assChnBankAcc/toListPage.do?chnId="+chnId);
                                break;
                        }
                    }
                    SetIframe_height();
                }
            });
            initForm();//初始化表单
            // initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
            //searchBtnEvent();//查询按钮事件
            //clearBtnEvent();//清空按钮事件

            initData();//初始化数据
        });
        $.extend(true, pageInApp, {
            pageInTab: pageInTab
        });

        function initComBox() {
            $("#coopTypCd").ligerComboBox({
                selectBoxWidth: 240,
                selectBoxHeight: 150,
                treeLeafOnly: false, //限制只能选叶节点，父节点不能点击
                valueField: 'key',
                textField: 'value',
                onlyParentNode: true, //只保留树的父节点值
                tree: {
                    data:${coopTypCdListJson},
                    idFieldName: 'key',
                    textFieldName: 'value',
                    parentIcon: "none",
                    childIcon: "none",
                },
            });

            $("#rgnCd").ligerComboBox({
                selectBoxWidth: 240,
                selectBoxHeight: 150,
                treeLeafOnly: false, //限制只能选叶节点，父节点不能点击
                valueField: 'key',
                textField: 'value',
                onlyParentNode: true, //只保留树的父节点值
                tree: {
                    data:${provinceKVListJson},
                    idFieldName: 'key',
                    textFieldName: 'value',
                    parentIcon: "none",
                    childIcon: "none",
                },
            });
        }

		//初始化数据
	    function initData(){
	    	initForm();//初始化表单
	    }
		//初始化表单
	    function initForm(){
	    	$("#assTrailCarChnFormSet").ligerForm({
				validate: true
			});
		};

        function cstTypCdFun(val) {
            if("1" == val){//自然人
                $("#succDiv").css("display","none");
                $("#corpRepDiv").css("display","none");
                $("#regCapAmtDiv").css("display","none");
                $("#expDtDiv").css("display","none");
            }else{
                $("#succDiv").css("display","block");
                $("#corpRepDiv").css("display","block");
                $("#regCapAmtDiv").css("display","block");
                $("#expDtDiv").css("display","block");
            }
        };
	    
		//保存信息
		function saveAssTrailCarChnInfo(){
			var ligerForm = liger.get("assTrailCarChnFormSet");

			//取消输入框验证
            var _channelTypeCd= liger.get("channelTypeCd").getValue();//渠道类型 1：自然人  2：法人
            if (_channelTypeCd == "1") {
                ligerForm.setFieldValidate("succ", {required: false});//社会统一信用代码
                ligerForm.setFieldValidate("corpRep", {required: false});//法人代表
                ligerForm.setFieldValidate("regCapAmt", {required: false});//注册资本
                ligerForm.setFieldValidate("expDt", {required: false});//营业期限
            }

            if (!ligerForm.valid()) {
				$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
				return false; //验证不通过，不执行以下代码
			}

			//获取ID-为空执行添加,否则修改
			var chnId = $("#chnId").val();
			var data = ligerForm.getData();//获取表单数据
			data["id"] = chnId;
            var fileParams = getUploadResultParams();//获取附件上传的信息
            data["fileParams"] = JSON.stringify(fileParams);
			//默认新增信息
			var url = '<%=path%>/ass/assTrailCarChannel/add.do';
			if(chnId){
				url = '<%=path%>/ass/assTrailCarChannel/modify.do';
			}
			var wait_dialog = null;
			$.ajax({
				type: 'post',
				dataType: 'json',
				data: data,
				url: url,
				beforeSend: function(){
					wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
				},
				success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                        $("#chnId").val(msg.data);//新增成功后 赋值
					}else{
						$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					}
				}
			});
		}

	</script>
</body>
</html>